import 'package:flutter/material.dart';
import 'package:flutter_study/DrawerDemo.dart';
import 'package:flutter_study/TabBarDemo.dart';
import 'package:flutter_study/layout/ColumnDemo.dart';
import 'package:flutter_study/layout2/ListViewDemo.dart';
import 'package:flutter_study/provider/CountProvider.dart';
import 'package:flutter_study/route/RouteDemo.dart';
import 'package:flutter_study/route/RouteDemo2.dart';
import 'package:flutter_study/route/RouteMain.dart';
import 'package:flutter_study/widget/ClickDemo.dart';
import 'package:flutter_study/widget/InputDemo.dart';
import 'package:flutter_study/widget/MyString.dart';
import 'package:flutter_study/widget/ProgressDemo.dart';
import 'package:flutter_study/widget/TextDemo.dart';
import 'package:flutter_study/widget/WidgetMain.dart';
import 'package:provider/provider.dart';

import 'BottomNavigatorDemo.dart';
import 'OtherDemo/DebugDemo.dart';
import 'OtherDemo/PerformancerDemo.dart';
import 'OtherDemo/ProviderDemo.dart';
import 'TableAndCardDemo/CardDemo.dart';
import 'TableAndCardDemo/TableDemo1.dart';
import 'TableAndCardDemo/TableDemo2.dart';
import 'TableAndCardDemo/TableMainDemo.dart';
import 'dialog/DialogDemo.dart';
import 'layout/LayoutMain.dart';
import 'layout2/GridViewDemo.dart';
import 'layout2/Layout2MainDemo.dart';
import 'layout2/ListTileDemo.dart';

///main
void main() {
  // runApp(ChangeNotifierProvider(
  //   create: (context) => CountProvider(),
  //   child: MyApp(),
  // ));

  runApp(MultiProvider(
    providers: [
      ChangeNotifierProvider(
        create: (context) => CountProvider(),
      )
    ],
    child: MyApp(),
  ));
}

///1.路由注册
///2.路由监听（路由拦截）
///2.1 desc:只要在路由中注册的route都不会被路由拦截器拦截到
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      // home: MyHomePage(title: 'Flutter Demo Home Page'),
      routes: {
        MyString.homePage: (context) => MyHomePage(title: "Home Page"),
        // MyString.widgetMain: (context) => WidgetMain(),
        MyString.routeDemo: (context) => RouteMain(),
        MyString.layoutMain: (context) => LayoutMain(),
        MyString.textDemo: (context) => TextDemo(title: "Text Demo"),
        MyString.progressDemo: (context) =>
            ProgressWidgetDemo(title: "Progress demo"),
        MyString.clickDemo: (context) => ClickDemo(title: "Click  Demo"),
        MyString.inputDemo: (context) => InPutDemo(title: "Input Demo"),
        "route1": (context) => RouteDemo(title: "路由演示1"),
        "route2": (context) => RouteDemo2(title: "路由演示2"),
        "menu1": (context) => MenuPage1(title: "菜单界面"),
        "menu2": (context) => MenuPage2(title: "菜单界面"),
        "columnDemo": (context) => ColumnDemo(),
        "tabBar": (context) => TabBarDemo(),
        "drawer": (context) => DrawerDemo(),
        "bottomNavigator": (context) => BottomNavigatorDemo(),
        "layoutMain2": (context) => LayoutMain2Demo(),
        "listView": (context) => ListViewDemo(),
        "gridView": (context) => GridViewDemo(),
        "dialog": (context) => DialogDemo(),
        "table": (context) => TableMainDemo(),
        "table1": (context) => TableDemo1(),
        "table2": (context) => TableDemo2(),
        "card": (context) => CardDemo(),
        "listTile": (context) => ListTileDemo(),
        "otherDemo": (context) => PerformanceDemo(),
        "debugDemo": (context) => DebugDemo(),
        "providerDemo": (context) => ProviderDemo(),
      },
      //2.路由拦截
      onGenerateRoute: (RouteSettings s) {
        print("打印路由拦截：name:  ${s.name} \n arguments:  ${s.arguments}");
        switch (s.name) {
          case MyString.widgetMain:
            return MaterialPageRoute(builder: (context) {
              return WidgetMain();
            });
        }
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

///elevation 阴影
///leading 左边
///actions
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          centerTitle: true,
          elevation: 10.0,
        ),
        body: Center(
          child: Column(
            children: [
              RaisedButton(
                onPressed: () {
                  Navigator. /*popAndPushNamed*/ pushNamed(
                      context, MyString.widgetMain);
                },
                child: Text("基础组件"),
                color: Colors.blue,
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, MyString.routeDemo);
                },
                child: Text("路由"),
                color: Colors.blue,
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, MyString.layoutMain);
                },
                child: Text("布局"),
                color: Colors.blue,
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "tabBar");
                },
                child: Text("tabBar('类似于Viewpager与TabLayout的效果')"),
                color: Colors.blue,
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "drawer");
                },
                child: Text("drawer('类似于drawerLayout的效果')"),
                color: Colors.blue,
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "bottomNavigator");
                },
                child: Text("底部选项卡"),
                color: Colors.blue,
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "layoutMain2");
                },
                child: Text("layoutMain2"),
                color: Colors.blue,
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "dialog");
                },
                child: Text("dialog"),
                color: Colors.blue,
              ),
              ElevatedButton(
                  onPressed: () {
                    Navigator.pushNamed(context, "table");
                  },
                  child: Text("表格演示和卡片")),
              ElevatedButton(
                  onPressed: () {
                    Navigator.pushNamed(context, "otherDemo");
                  },
                  child: Text("性能优化")),
              ElevatedButton(
                  onPressed: () {
                    Navigator.pushNamed(context, "debugDemo");
                  },
                  child: Text("debug")),
              ElevatedButton(
                  onPressed: () {
                    Navigator.pushNamed(context, "providerDemo");
                  },
                  child: Text("Provider全局状态管理")),
            ],
          ),
        ));
  }
}
